package com.lhx.arrray.bilibili;

//求滑动窗口最大的值
public class array_bili_16 {
    public static double findMaxAverage(int[] nums, int k) {
       int sum = 0;
       for(int i=0; i<k; i++) {
           sum = sum + nums[i];
       }
       int max = sum;
       for(int i=k; i<nums.length; i++) {
           sum = sum + nums[i] - nums[i-k];
           max = Math.max(max, sum);
       }
       return 1.0 * max / k;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,12,-5,-6,50,3};
        double max = findMaxAverage(nums,4);
        System.out.println("最大值为："+max);
    }
}
